//
//  LZTMainViewController.swift
//  LZTWeibo
//
//  Created by Yin jianxun on 16/8/10.
//  Copyright © 2016年 YinJianxun. All rights reserved.
//

import UIKit

class LZTMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //实例化 自定义tabBar
        let tabBar = LZTTabBar()
        
        //设置代理
        tabBar.lztDelegate = self
        
        //self.tabBar 只读
        //通过KVC
        setValue(tabBar, forKey: "tabBar")
        
        //设置首页 Home
        addChildVc(LZTHomeViewController(), imageName: "tabbar_home", title: "首页")
        
        //设置消息 Message
        addChildVc(LZTMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        
        //设置发现 Discover
        addChildVc(LZTDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        
        //设置我 Profile
        addChildVc(LZTProfileViewController(), imageName: "tabbar_profile", title: "我")
        
    }
    
    func addChildVc(viewController: UIViewController, imageName: String, title: String) {
        
        //设置 title
//        viewController.navigationItem.title = title
//        viewController.tabBarItem.title = title
        viewController.title = title
        
        //设置tabBar的文字颜色
        viewController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //设置tabBar 图片 - 设置tabBar的控件颜色
        viewController.tabBarItem.image = UIImage(named: imageName)
        viewController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: viewController))
        
    }
 
}

extension LZTMainViewController: LZTTabBarDelegate{
    func tabBarButtonClick() {
        
        if !LZTUserAccountViewModel.sharedTools.isLogin {
            
            print("请先登录")
            return
        }
        //撰写按钮Vc
        let composeVc = LZTComposeViewController()
        
        //modal出新的vc
        self.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
        
    }
}





